<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>02.找出字符串中的所有数字</title>
        <script>
            var str = 'fdfjoe34rlemkdf274ldfldf6ldflldlfdf909';
            var arr = [];
            // 建立一个临时变量
            var tmp = '';
            function findNumber (str) {
                for ( var i = 0, len = str.length; i < len; i++ ) {
                    if ( str.charAt(i) >= '0' && str.charAt(i) <= '9' ) {
                        tmp += str.charAt(i);
                        // arr.push(str.charAt(i));
                    } else {
                        if ( tmp ) {
                            arr.push(tmp);
                            tmp = '';
                        }
                    }
                }

                if ( tmp ) {
                    arr.push(tmp);
                    tmp = '';
                }

                return arr;
            }

            // result：[34, 274, 6, 909]
            alert(findNumber (str));
        </script>
    </head>
    <body>

    </body>
</html>
